import jwtToken from './../../helpers/jwt'
export default {
    actions: {
        loginRequest({dispatch}, formData) {
            return axios.post("/login", formData).then(response => {//登录接口
                dispatch('loginSuccess',response.data)
            })
            /* return axios
              .post("/api/login", formData)
              .then(response => {
                dispatch("loginSuccess", response.data);
              }) */;
        },
        loginSuccess({dispatch}, tokenResponse) {
            jwtToken.setToken(tokenResponse.token)
            jwtToken.setAuthId(tokenResponse.auth_id)
            dispatch('setAuthUser')
        },
        logoutRequest({dispatch}) {
           return axios
             .post("/logout")//退出接口
             .then(response => {
               jwtToken.removeToken();
               dispatch("unsetAuthUser");
             });
        }
    }
}